package com.gaojinqi.sys.modular.rbac.model;

import com.gaojinqi.base.common.model.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;

import static com.gaojinqi.sys.modular.rbac.model.RolePermissionMapping.TABLE_NAME;


/**
 * 角色-权限 映射 实体
 *
 * @author gaojinqi
 * @version 1.0
 * @since 2020年04月20日
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Entity
@Table(name = TABLE_NAME)
@org.hibernate.annotations.Table(appliesTo = TABLE_NAME, comment = "系统角色权限关联表")
public class RolePermissionMapping extends BaseEntity {

    private static final long serialVersionUID = 1881655627529970972L;

    public static final String TABLE_NAME = "sys_role_permission_mapping";

    @Id
    @GeneratedValue(generator = TABLE_NAME + "_uuid")
    @GenericGenerator(name = TABLE_NAME + "_uuid", strategy = "uuid")
    @Column(columnDefinition = "varchar(32)  COMMENT '关联ID'")
    private String mappingId;

    @ManyToOne
    @JoinColumn(name = "roleId", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
    private Role role;

    @ManyToOne
    @JoinColumn(name = "permissionId", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
    private Permission perm;

}
